﻿using StableDiffusionTools.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StableDiffusionTools.Controls
{
    public class ToolStripEx : ToolStrip
    {
        public bool ClickThrough { get; set; } = true;

        public ToolStripEx() : base()
        {

        }

        public ToolStripEx(params ToolStripItem[] items) : base(items)
        {

        }
        protected override void WndProc(ref Message m)
        {
            //.NET ToolStrip classes do not support "Click Through" when their parent Form lacks focus.
            //https://learn.microsoft.com/en-us/archive/blogs/rickbrew/how-to-enable-click-through-for-net-2-0-toolstrip-and-menustrip
            base.WndProc(ref m);

            if (ClickThrough &&  m.Msg == (int)WindowMessage.MouseActivate && m.Result == (IntPtr)MouseActivateMessage.ActivateAndEat)
                m.Result = (IntPtr)MouseActivateMessage.Activate;
        }
    }
}
